<template>
	<view class="preorder-info">
		<view class="info">
			<image :src="info.avatar"></image>
			<view class="info-right">
				<text class="name">{{ info.username }}</text>
				<text class="level">{{ info.star }}星</text>
			</view>
		</view>
		<view class="line">
			
		</view>
		<scroll-view scroll-x class="date-list">
			<!-- <view class="date-list">
				
			</view> -->
			<view :class="[((!flag)&&index==currentIndex)?'item,active':'item']" v-for="(item,index) in date" @click="myChooseDate(index)">
				<text class="type" v-if="(!flag)&&index==currentIndex" :style="[((!flag)&&index==currentIndex)?{color:'#fff',fontweight:'bold',background:'#0f0'}:{}]">√</text>
				<text class="type" v-else>可约</text>
				<view class="date" :style="[((!flag)&&index==currentIndex)?{color:'#000',fontWeight:'bold'}:{}]">
					<view class="w">{{ item.week }}</view>
					<view class="w">{{ item.dt.slice(5) }}</view>
				</view>
			</view>
		</scroll-view>
			

		<view class="time">
			<view class="title">
				请选择时间段
			</view>
			<view class="time-list">
				<view :class="[((!flags)&&index==currentIndexs)?'item,active':'item']" v-for="(item,index) in time" @click="myChooseTime(index)">
					<text class="type" v-if="(!flags)&&index==currentIndexs" :style="[((!flags)&&index==currentIndexs)?{color:'#fff',fontweight:'bold',background:'#0f0'}:{}]">√</text>
					<text class="type" v-else>可约</text>
					<text class="times">{{ item }}</text>
				</view>
			</view>
		</view>
		<view class="foot">
			<view class="warn">{{ showTip }}</view>
			<view class="button" @click="goPreOrder">去预约</view>
		</view>
	</view>
</template>

<script>
	import {handleTime} from '../../utils/FormatDate.js'
	export default {
		data() {
			return {
				flag:false,
				flags:false,
				currentIndex:-1,
				currentIndexs:-1,
				info:{},
				date:[],
				time:['09:00-12:00','14:00-18:00']
			};
		},
		computed:{
			showTip(){
				if(this.currentIndex==-1){
					return '未选定日期'
				}else if(this.currentIndexs==-1){
					return '未选定时间段'
				}else{
					return '已完成'
				}
			}
		},
		onLoad(options) {
			// handleTime(new Date)
			console.log(options,'ooopp')
			if(options.info){
				this.info = JSON.parse(options.info)
			}
			if(options.infos){
				
				let aa = JSON.parse(options.infos)
				console.log(aa,'222')
				// try {
				//   // const data = JSON.parse(jsonString);
				//   let a = JSON.parse(options.infos)
				//   console.log(a,'222')
				//   // 处理解析后的数据
				// } catch (e) {
				//   console.error('JSON解析错误：', e);
				//   // 处理错误，如提示用户或记录日志
				// }
				// infos: "{"id":2,"username":"小李","avatar":"https://ts1.cn.mm.bing.net/th/id/R-C.7a4bfcfc3b5fde83c356c63a53f95ef6"
				// co
				// console.log(options.infos,'infos',JSON.parse(options.infos))
				// let a = JSON.parse(options.infos)
				// console.log(a,'22233')
			}
			this.date = handleTime()
			console.log(this.date,'dt')
			if(options.currentIndex&&options.currentIndexs){
				this.currentIndex = Number(options.currentIndex)
				this.currentIndexs = Number(options.currentIndexs)
				console.log(this.currentIndex,this.currentIndexs)
			}
			
			
		},
		methods:{
			myChooseDate(index){
				this.currentIndex =index
			},
			myChooseTime(index){
				
				this.currentIndexs =index
				console.log(index,this.currentIndexs)
			},
			goPreOrder(){
				let date = JSON.stringify(this.date[this.currentIndex])
				let infos
				if(this.info){
					infos = JSON.stringify(this.info)
				}
				console.log(date,'dss')
				uni.navigateTo({
					url:`/subPackage/OrderLog/OrderLog?info=${infos}&&date=${date}&&time=${this.time[this.currentIndexs]}&&currentIndex=${this.currentIndex}&&currentIndexs=${this.currentIndexs}`
				})
			}
		}
	}
</script>

<style lang="scss">
.preorder-info{
	width: 100%;
	padding: 20rpx;
	.info{
		display: flex;
		align-items: center;
		margin-bottom: 40rpx;
		image{
			width: 100rpx;
			height: 100rpx;
			margin-right: 20rpx;
			border-radius: 20rpx;
		}
		.info-right{
			width: 100%;
			padding-right: 30rpx;
			display: flex;
			justify-content: space-between;
			.name{
				font-weight: bold;
			}
			.level{
				background: #0f0;
				color: #fff;
				padding: 4rpx 10rpx;
				border-radius: 0 15rpx 0 15rpx;
			}
		}
	}
	.line{
		width: 100%;
		height: 14rpx;
		background: #ccc;
		margin-bottom: 20rpx;
	}
	.date-list{
		width: 100%;
		// border: 1px solid #0f0;
		white-space: nowrap;
		// display: flex;
		.item{
			width: 100rpx;
			height: 160rpx;
			// border: 1px solid #000;
			position: relative;
			display: inline-block;
			text-align: center;
			background: #e1e1e1;
			margin: 0 10rpx;
			border-radius: 10rpx;
			
			.type{
				font-size: 22rpx;
				position: absolute;
				right: 0;
				background: #bbb;
				padding: 4rpx 6rpx;
				border-radius: 0 10rpx;
				
			}
			.date{
				// font-weight: bold;
				padding-top: 60rpx;
				font-size: 26rpx;
				color:'#999';
				.w{
					line-height: 40rpx;
				}
			}
		}
		.active{
			border: 1px solid #0f0;
		}
		
	}
	.time{
		.title{
			font-weight: bold;
			line-height: 100rpx;
			border-bottom: 1px solid #ccc;
			margin-top: 30rpx;
		}
		.time-list{
			display: flex;
			flex-wrap: wrap;
			margin-top: 20rpx;
			.item{
				width: 30%;
				height: 120rpx;
				// border: 1px solid #000;
				margin: 10rpx;
				position: relative;
				text-align: center;
				background: #e1e1e1;
				border-radius: 10rpx;
				overflow: hidden;
				.type{
					font-size: 22rpx;
					position: absolute;
					right: 0;
					background: #bbb;
					padding: 4rpx 6rpx;
					border-radius: 0 10rpx;
				}
				.tip{
					position: absolute;
					right: 0;
					font-size: 22rpx;
					background: #bbb;
					padding: 4rpx 6rpx;
				}
				.times{
					text-align: center;
					line-height: 140rpx;
					padding-top: 36rpx;
				}
			}
		}
	}
	.foot{
		width: 100%;
		display: flex;
		justify-content: space-between;
		height: 80rpx;
		line-height: 80rpx;
		position: fixed;
		bottom: 0;
		// border: 1px solid #000;
		.warn{
			width: 100%;
			color: red;
			text-align: center;
		}
		.button{
			width: 400rpx;
			line-height: 80rpx;
			text-align: center;
			background: #1afa29;
			color: #fff;
		}
	}
}
</style>
